;
(function() {
	module.exports = {
		save: function() {
			db.update(config.dbname.domain, this._id, this);
		},
		destroy: function() {
			db.remove(config.dbname.domain, this._id);
		},
		getUrl: function() {
			var domainInfo = this;
			var url = domainInfo.is_secondary_domain ? "http://" + domainInfo.domain + ".dotnar.com" : "http://www." + domainInfo.domain;
			if (domainInfo.port && domainInfo.port != 80) {
				url += ":" + domainInfo.port;
			}
			return url;
		},
		//不安全，修改二级地址
		_updateSecondaryDomain: function(domain) {
			if (!this.is_secondary_domain) {
				throwCusError("此域名无法当成二级域名进行修改")
			}
			domain = String(domain).toLowerCase();
			domain = tld.getDomain(domain);
			if (!domain) {
				throwCusError("域名格式错误");
			}
			this.domain = domain;
			this.save();
		}
	};
	var db = require("../db/index");
	var config = require("../_include/config");
	var db_table_name = config.dbname.domain;
	var db_id_prefix = config.dbIdPrefix.domain;
	var tld = require('tldjs');
}());